----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    16:39:08 04/16/2010 
-- Design Name: 
-- Module Name:    GPIO_Module - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity GPIO_Module is
    Port ( wb_clk : in  STD_LOGIC;
           wb_stb : in  STD_LOGIC;
           wb_ack : out  STD_LOGIC;
           wb_data_i : in  STD_LOGIC_VECTOR (31 downto 0);
           wb_cyc : in  STD_LOGIC;
           gpio_o_1 : out  STD_LOGIC;
			  gpio_o_2 : out  STD_LOGIC;
			  gpio_o_3 : out  STD_LOGIC;
			  gpio_o_4 : out  STD_LOGIC;
           wb_data_o : out  STD_LOGIC_VECTOR (31 downto 0);
           gpio_i : in  STD_LOGIC;
           wb_we : in  STD_LOGIC;
			  wb_adr_i : in  STD_LOGIC_VECTOR (1 downto 0));
end GPIO_Module;

architecture Behavioral of GPIO_Module is

begin

P1: process(wb_stb, wb_cyc)
begin

	if wb_cyc = '1' and wb_stb = '1' then
		wb_ack <= '1';
		
	if(wb_we = '1')then 
		if wb_adr_i = "00" then
			if wb_data_i = "00000000000000000000000000000001" then gpio_o_1 <= '0';
			elsif  wb_data_i = "00000000000000000000000000000010" then gpio_o_1 <= '1';
			end if;

		elsif wb_adr_i = "01" then
			if wb_data_i = "00000000000000000000000000000001" then gpio_o_2 <= '0';
			elsif  wb_data_i = "00000000000000000000000000000010" then gpio_o_2 <= '1';
			end if;

		elsif wb_adr_i = "10" then
			if wb_data_i = "00000000000000000000000000000001" then gpio_o_3 <= '0';
			elsif  wb_data_i = "00000000000000000000000000000010" then gpio_o_3 <= '1';
			end if;

		elsif wb_adr_i = "11" then
			if wb_data_i = "00000000000000000000000000000001" then gpio_o_4 <= '0';
			elsif  wb_data_i = "00000000000000000000000000000010" then gpio_o_4 <= '1';
			end if;
		else
		wb_ack <= '0';
			
		end if;
	else
		if wb_adr_i = "00" then
			if gpio_i = '0' then wb_data_o <= "00000000000000000000000000000001";
			elsif gpio_i = '1' then wb_data_o <= "00000000000000000000000000000010";
			end if;
		end if;
	end if;
	
end if;
end process;


end Behavioral;

